home *** CD-ROM | disk | FTP | other *** search
- package sun.net.www;
-
- import java.io.FilterInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.URL;
- import sun.net.ProgressData;
-
- public class MeteredStream extends FilterInputStream {
- private static int total_need;
- private static int total_read;
- private static int total_connections;
- int expected;
- int count;
- public URL url;
- boolean closed;
-
- private static synchronized void globalJustRead(int var0) {
- total_read += var0;
- }
-
- private static synchronized void updateExpected(int var0) {
- total_need += var0;
- }
-
- private static synchronized void addConnection(MeteredStream var0) {
- ++total_connections;
- }
-
- private static synchronized void removeConnection(MeteredStream var0) {
- --total_connections;
- total_read -= var0.expected;
- total_need -= var0.expected;
- }
-
- public static synchronized ProgressReport checkProgress(ProgressReport var0) {
- return var0.set(total_read, total_need, total_connections);
- }
-
- public MeteredStream(InputStream var1, int var2, URL var3) {
- this(var1, var2);
- this.url = var3;
- }
-
- public MeteredStream(InputStream var1, int var2) {
- super(var1);
- this.closed = false;
- updateExpected(var2);
- this.expected = var2;
- addConnection(this);
- }
-
- private final void justRead(int var1) {
- if (this.count + var1 > this.expected) {
- var1 = this.expected - this.count;
- }
-
- this.count += var1;
- globalJustRead(var1);
- ProgressData.pdata.update(this.url, this.count, this.expected);
- }
-
- public int read() throws IOException {
- int var1 = super.read();
- if (var1 != -1) {
- this.justRead(1);
- }
-
- return var1;
- }
-
- public int read(byte[] var1, int var2, int var3) throws IOException {
- int var4 = super.read(var1, var2, var3);
- if (var4 != -1) {
- this.justRead(var4);
- }
-
- return var4;
- }
-
- public long skip(long var1) throws IOException {
- var1 = super.skip(var1);
- if (var1 != -1L) {
- this.justRead((int)var1);
- }
-
- return var1;
- }
-
- public void close() throws IOException {
- super.close();
- if (!this.closed) {
- this.closed = true;
- this.justRead(this.expected - this.count);
- removeConnection(this);
- }
-
- ProgressData.pdata.unregister(this.url);
- }
-
- protected void finalize() {
- if (!this.closed) {
- this.closed = true;
- this.justRead(this.expected - this.count);
- removeConnection(this);
- }
-
- ProgressData.pdata.unregister(this.url);
- }
- }
-